/* item.cpp
* methods definitions
*/
#include "item.h"
#include "consts.h"

/* Constructor */
Item::Item(int id, int value1, int value2, int value3) {
  _id = id;
  _value[0] = value1;
  _value[1] = value2;
  _value[2] = value3;
  // A small disappearing effect
  _shine = FRAMERATE * 2;
  
  char path[64];
  strcpy(path, "images/items/");
  // Hardcoded due to the lack of the time
  switch(id) {
    default: strcat(path, "item_shotgun.bmp"); break;
    case ITEM_HEALTH: strcat(path, "item_health.bmp"); break;
  }
  __setBitmap(load_bitmap(path, NULL));
  __setBoundingBox(0, 0, __getSprite()->w, __getSprite()->h);
  __enableBoundingBox(1);
}

/* Destructor */
Item::~Item() {
  if ( __getSprite() )
    destroy_bitmap(__getSprite());
}

/* __update() */
void Item::__update() {
  // A shiny effect to catch people eyes
  if ( --_shine < 4 ) {
    __hide(1);
    if ( _shine <= 0 ) {
      __hide(0);
      _shine = FRAMERATE * 2;
    }
  }
  
}
int Item::__getCustomValue(int n) {
 if ( n > 3 || n < 1 ) n = 0;
 else --n;
 return _value[n];
}

int Item::__getId() { return _id; }
